home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14218 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.0 KB  |  94 lines

  1. Path: mail2news.demon.co.uk!devmaccn.demon.co.uk
  2. From: Alan Griffiths <aGriffiths@ma.ccngroup.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: STL and namespaces?
  5. Date: Fri, 29 Mar 1996 15:26:16 GMT
  6. Organization: CCN Market Analysis
  7. Distribution: world
  8. Message-ID: <85140771wnr@ma.ccngroup.com>
  9. References: <314F1A4C.2868@ix.netcom.con>
  10. Reply-To: aGriffiths@ma.ccngroup.com
  11. X-NNTP-Posting-Host: devmaccn.demon.co.uk
  12. X-Broken-Date: Friday, Mar 29, 1996 15.26.16 GMT
  13. X-Newsreader: Newswin Alpha 0.6
  14. X-Mail2News-Path: devmaccn.demon.co.uk
  15.  
  16. In article: <314F1A4C.2868@ix.netcom.con>  Robert Kleemann <goose@ix.netcom.con> writes:
  17. > I've been using The HP STL (Dec95 version) with the Microsoft VC4 
  18. > Compiler for the past few months and have taken Microsoft's 
  19. > recommendation to stick all the STL include files in its own namespace 
  20. > to avoid global operator conflicts with Microsoft's class library (MFC). 
  21. >  The name std is recommend by ANSI for the standard template library 
  22. > namespace.
  23. > After tweaking some of the STL files this has worked pretty well except 
  24. > for the following problems:
  25. > 1) global operators cannot be accessed without the namespace prefix eg:
  26. > std::string s1;
  27. > std::string s2;
  28. > if (s1==s2) // this doesn't work
  29. >     ;
  30. > if (std::operator==(s1,s2)) // this does work
  31. >     ;
  32.  
  33.   using namespace std;
  34.   string s1;
  35.   string s2;
  36.   if (s1 == s2) 
  37.  
  38. > 2) STL algorithms that use global operators don't work on classes that 
  39. > define these operators eg:
  40. > class C
  41. > {
  42. >     C();
  43. >     C(const C& c);
  44. >     C& operator=(const C& c);
  45. >     friend bool operator==(const C& c1, const C& c2);
  46. > };
  47. > inline bool operator==(const C& c1, const C& c2)
  48. > {
  49. >     return true;
  50. > }
  51. namespace std
  52. {
  53.   inline bool operator==(const C& c1, const C& c2)
  54.   {
  55.       return true;
  56.   }
  57. }
  58. > void main()
  59. > {
  60. >     std::list<C> container;
  61. >     std::list<C>::iterator i;
  62. >     // the following line will not compile because 
  63. >     // find require operator== to be defined for C
  64. >     i = std::find( container.begin(), container.end(), 
  65. >         C() );
  66. > }
  67. > The first problem is expected and and although it makes the code less 
  68. > readable, it is not a major problem.  The second problem has no clear 
  69. > workaround and makes me want to stop using namespaces.
  70. > My question is: are other people out there using STL with namespaces?  
  71. > Have you run into these problems?  Have you found better workarounds?  
  72.  
  73. Avoid the MSVC4 compiler - problem (2) is a defect in the MS 
  74. implementation of namespaces! ;)
  75.  
  76. > Can I expect these namespace problems to be fixed in future STL 
  77. > implementations or would I be better off including STL in global space 
  78. > and instead try sticking MFC in a namespace.
  79.  
  80. You may hope that the problem will be fixed in a future MSVC 
  81. implementation.
  82.  
  83. Alan Griffiths               | Also editor of: The ISDF Newsletter
  84. Senior Systems Consultant,   | (An Association of C and C++ Users publication)
  85. CCN Group Limited.           | (ISDF editor  : isdf@octopull.demon.co.uk)
  86. (agriffiths@ma.ccngroup.com) | (For ACCU see : http://bach.cis.temple.edu/accu)
  87.  
  88.